package com.fd.controller;
import com.fd.bean.Order;
import com.fd.dao.OrderDao;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import java.util.Collection;
@Controller
@RequestMapping("/order")
public class OrderController {
    private OrderDao orderDao = new OrderDao();
    @RequestMapping(value = "/list", method = RequestMethod.GET)
    public String list(Model model) {
        //获取用户列表
        Collection<Order> all = orderDao.getAll();
        model.addAttribute("orderList", all);
        return "order/list";
    }
    @RequestMapping(value = "/{id}", method = RequestMethod.DELETE)
    public String delete(@PathVariable("id") Integer id) {
        //执行删除操作
        System.out.println("id = " + id);
        orderDao.delete(id);
        return "redirect:/order/list";
    }
    @RequestMapping(value = "/{id}", method = RequestMethod.PUT)
    public String update(@PathVariable("id") Integer id) {
        //执行更新操作
        System.out.println("id = " + id);
        orderDao.get(id).setCode("修改过后的订单");
        return "redirect:/order/list";
    }
    @RequestMapping(value = "/save", method = RequestMethod.POST)
    public String save(Order order) {
        //执行添加操作
        orderDao.save(order);
        return "redirect:/order/list";
    }
}
